/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.edu.amu.wmi.kino.visualjavafx.visualjavafxgui.editor.visual.widgets;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import org.netbeans.api.visual.widget.Scene;
import org.netbeans.api.visual.widget.Widget;
import pl.edu.amu.wmi.kino.visualjavafx.model.objects.Canvas;
import pl.edu.amu.wmi.kino.visualjavafx.model.objects.Frame;

/**
 *
 * @author psychollek
 */
public class CanvasWidget extends Widget{

    private Frame frame;
    private Canvas canvas;

    public CanvasWidget(Scene scene, Frame frame, Canvas canvas){
        super(scene);
        this.frame = frame;
        this.canvas = canvas;
        this.setBoundaries();
    }

    private void setBoundaries(){
        Point p = new Point(0,0);
        this.setPreferredLocation(p);
        Dimension d = new Dimension(frame.getWidth(),frame.getHeight());
        this.setPreferredSize(d);
    }

    @Override
    protected java.awt.Rectangle calculateClientArea(){
        Dimension d = this.getPreferredSize();
        Point p = this.getPreferredLocation();
        java.awt.Rectangle r = new java.awt.Rectangle(p,d);
        return(r);
    }

    @Override
    protected void paintWidget(){
        Graphics2D g = getGraphics ();
        g.setColor(canvas.getBgColor());
        g.fillRect(0, 0, frame.getWidth(), frame.getHeight());
        g.setColor (Color.BLACK);
        g.drawRect(0,0,frame.getWidth(), frame.getHeight());
    }

}
